require('./common/runtime.js')
require('./common/vendor.js')
require('./common/main.js')

App({
    onLaunch() {
        wx.cloud.init({
            env: 'joe-6g432tv4b8eb2c11', // 根据实际情况填写环境 ID
            traceUser: true,
        });
        // 展示本地存储能力
        const logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)
        this.preloadImages();
    },
    globalData: {
        "key": "T3XBZ-I2QC5-L24IP-IMPZQ-352GZ-OSF7Z ",
        "env": "joe-6g432tv4b8eb2c11",
        "service": "demo",
        "maxDistance": 5000000000000,
        "contextPath": "/tianqiao",
        preloadedImages: {}
    },
    preloadImages: function () {
        const imageUrls = [
            'https://6a6f-joe-6g432tv4b8eb2c11-1322962961.tcb.qcloud.la/%E4%BA%AC%E9%9F%B5%E5%A4%A9%E6%A1%A5%E6%89%8B%E7%BB%98%E5%9C%B0%E5%9B%BE2.5.jpg?sign=351414538f6065d35ec033e044077857&t=1719719088'
        ];

        imageUrls.forEach(url => {
            wx.downloadFile({
                url: url,
                success: res => {
                    if (res.statusCode === 200) {
                        this.globalData.preloadedImages[url] = res.tempFilePath;
                        wx.setStorageSync(url, res.tempFilePath); // 缓存图片路径
                    }
                },
                fail: err => {
                    console.error('图片预加载失败', err);
                }
            });
        });
    }
})